#!/bin/bash

# =============================================
# Finna Spring Boot 项目启动脚本
# =============================================

set -e

echo "🚀 启动 Finna Spring Boot 项目..."

# 检查Docker是否运行
if ! docker info > /dev/null 2>&1; then
    echo "❌ Docker 未运行，请先启动 Docker"
    exit 1
fi

# 检查Docker Compose是否安装
if ! command -v docker-compose > /dev/null 2>&1; then
    echo "❌ Docker Compose 未安装，请先安装 Docker Compose"
    exit 1
fi

# 创建必要的目录
echo "📁 创建必要的目录..."
mkdir -p logs
mkdir -p nginx/conf.d

# 构建项目
echo "🔨 构建项目..."
mvn clean package -DskipTests

# 启动服务
echo "🐳 启动 Docker 服务..."
docker-compose up -d

# 等待服务启动
echo "⏳ 等待服务启动..."
sleep 30

# 检查服务状态
echo "🔍 检查服务状态..."
docker-compose ps

# 显示服务信息
echo ""
echo "✅ 服务启动完成！"
echo ""
echo "📋 服务访问地址："
echo "  - API网关: http://localhost:8080"
echo "  - 认证服务: http://localhost:9100"
echo "  - 租户服务: http://localhost:9300"
echo "  - 用户服务: http://localhost:9200"
echo "  - Nacos控制台: http://localhost:8848/nacos"
echo "  - 数据库: localhost:5432"
echo "  - Redis: localhost:6379"
echo ""
echo "🔑 默认管理员账号："
echo "  - 用户名: admin"
echo "  - 密码: admin123"
echo ""
echo "📖 查看日志: docker-compose logs -f [服务名]"
echo "🛑 停止服务: docker-compose down"
echo ""
